package EinkauferActionListener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import DBConnection.DBConnectionGUI;
import DBConnection.DatabaseConnection;

public class DBOkListener implements ActionListener {

	
	private DBConnectionGUI connectionGUI;
	private String adress = null;;
	private String user =  null;
	private String password = null;
	private String dbname = null;
	
	public DBOkListener(DBConnectionGUI connectionGUI) {

			this.connectionGUI = connectionGUI;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		
		adress = connectionGUI.getJTextField_adresse().getText();
		dbname = connectionGUI.getJTextField_dbname().getText();
		user = connectionGUI.getJTextField_user().getText();
		password = connectionGUI.getJTextField_password().getText();

		DatabaseConnection dbc = null;
		try {
			dbc = new DatabaseConnection(adress, dbname, user, password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		//new Einkaufer(dbc);
		connectionGUI.getEinkaufer().setCn(dbc.getCn());
		connectionGUI.getEinkaufer().setup();
		
		connectionGUI.getJFrameConnection().setVisible(false);

	}

}
